﻿using Microsoft.AspNetCore.Http;
using Kang.ExtendMethod;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
using System;
using System.Dynamic;
using System.Text;

namespace Kang.Api.Filters
{
    public class PrintApiPathFilterAttribute : Attribute, IActionFilter
    {
        Logger logger = LogManager.GetCurrentClassLogger();

        public void OnActionExecuted(ActionExecutedContext context)
        {
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            string path = context.HttpContext.Request.Path;
            string info = $"Api:{path}";
            if (context.ActionArguments.ContainsKey("sign") && context.ActionArguments.ContainsKey("t"))
            {
                var sign = context.ActionArguments["sign"].ToString();
                var t = context.ActionArguments["t"].ToString().ToLong();
                info = $"{info}  Sign:{sign}  Time:{t}";
            }
            logger.Info(info);
        }
    }
}
